class LogModel {
  final DateTime timestamp;
  final String message;
  final LogLevel level;

  LogModel({required this.timestamp, required this.message, this.level = LogLevel.info});

  // 用于本地存储
  Map<String, dynamic> toMap() {
    return {
      'timestamp': timestamp.toIso8601String(),
      'message': message,
      'level': level.toString(),
    };
  }

  factory LogModel.fromMap(Map<String, dynamic> map) {
    return LogModel(
      timestamp: DateTime.parse(map['timestamp']),
      message: map['message'],
      level: LogLevel.values.firstWhere((e) => e.toString() == map['level']),
    );
  }
}

enum LogLevel { info, success, warning, error }